﻿Public Class DRGDISETCLASS
    Private ONSETID = Nothing
    Private OSNAME = Nothing
    Private STATUS = Nothing
    Private selectDrgdionset = "SELECT `onsetid` AS 'รหัสระยะเวลาที่ยามีผลต่อกัน', `osname` AS 'ระยะเวลาที่ยามีผลต่อกัน', `status` AS 'สถานะการเปิดใช้งาน' FROM drgdionset"

    Dim connect As CONDB = CONDB.NewConnection()

    Property ONSETID_ As Integer
        Get
            Return ONSETID
        End Get
        Set(value As Integer)
            ONSETID = value
        End Set
    End Property

    Property OSNAME_ As String
        Get
            Return OSNAME
        End Get
        Set(value As String)
            OSNAME = value
        End Set
    End Property

    Property STATUS_ As Boolean
        Get
            Return STATUS
        End Get
        Set(value As Boolean)
            If value = True Then
                STATUS = 1
            Else
                STATUS = 0
            End If
        End Set
    End Property

    Property selectDrgdionset_ As String
        Get
            Return selectDrgdionset
        End Get
        Set(value As String)
            selectDrgdionset = value
        End Set
    End Property

    Public Function insertDrgdionset() As Boolean
        If connect.GetTable("SELECT onsetid FROM drgdionset WHERE osname = '" & OSNAME & "'").Rows.Count > 0 Then
            MsgBox("มีข้อมูลความต่อเนื่องในการออกฤทธิยานี้อยู่ในระบบแล้ว")
        Else
            Try
                connect = CONDB.NewConnection()

                connect.ExecuteNonQuery("INSERT INTO drgdionset (osnam, status) VALUES ('" & OSNAME & "', '" & STATUS & "')")

                Return True
            Catch ex As Exception
                MsgBox(vbCrLf & ex.Message)
                Return False
            Finally
                connect.Dispose()
            End Try
        End If
    End Function

    Public Function editdrgdionset() As Boolean
        Try
            connect = CONDB.NewConnection()

            connect.ExecuteNonQuery("UPDATE drgdionset SET osname = '" & OSNAME & "', status = '" & STATUS & "' WHERE onsetid = '" & ONSETID & "'")

            Return True
        Catch ex As Exception
            MsgBox(vbCrLf & ex.Message)
            Return False
        Finally
            connect.Dispose()
        End Try
    End Function
End Class
